package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.events.PlayerCenterEvent;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.MainView;
	import com.lz.football.module.playerCenter.BattlearrayView;
	import com.lz.football.module.playerCenter.PlayerCenterListView;
	
	import common.base.GoodsUsePanel;
	
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.events.ListEvent;
	import lz.controls.managers.AnimationManager;

	/**
	 *使用体力卡 
	 * @author lake
	 * 
	 */	
	public class UsePhysicalGuideView extends Guide
	{
		public function UsePhysicalGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			initDialog_1();
			//disable
			MainView.playerSearchBtn.mouseEnabled = false;
			MainView.bagBtn.mouseEnabled = false;
		}
		/**
		 * 场景内对话框 
		 *	体力
			官方说法：没有体力时球员发挥大幅下跌并且有几率受伤！
			1L：时刻关注球员的体力是打联赛的必修课~
			2L：每小时回复一点，晚上10点补满~
			3L：还好只是联赛用！
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_14_1");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			showFuncIcon();
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showFuncIcon():void
		{
			MainView.playerBtn.visible = true;
			removeBgMark();
			//限制区域
			var rectPoint :Point = MainView.playerBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.playerBtn.width,MainView.playerBtn.height);
			step();
			//指向图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn =  MainView.playerBtn;
			arrowAngle = 0;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			//限制区域
			var rectPoint :Point = PlayerCenterListView.restoreBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PlayerCenterListView.restoreBtn.width,PlayerCenterListView.restoreBtn.height);
			step();
			//指向强力恢复
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  PlayerCenterListView.restoreBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Guide_openPhysicalUse",clickRestore);
		}
		/**
		 *点击强力恢复 
		 * @param e
		 * 
		 */		
		private function clickRestore(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Guide_openPhysicalUse",clickRestore);
			//限制区域
			var rectPoint :Point = GoodsUsePanel.firstItemSkin.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,GoodsUsePanel.firstItemSkin.width,GoodsUsePanel.firstItemSkin.height);
			step();
			//指向小背包第一格子
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  GoodsUsePanel.firstItemSkin;
			arrowAngle = -90;
			//事件
			GlobalDef.GameStage.addEventListener(ListEvent.ITEM_CLICK,itemClickh);
		}
		/**
		 *点击物品 
		 * @param e
		 * 
		 */		
		private function itemClickh(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ListEvent.ITEM_CLICK,itemClickh);
			//限制区域
			var rectPoint :Point = GoodsUsePanel.useBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,GoodsUsePanel.useBtn.width,GoodsUsePanel.useBtn.height);
			step();
			//指向使用
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  GoodsUsePanel.useBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Guide_use_item",useItemH);
		}
		/**
		 *使用物品 
		 * @param e
		 * 
		 */		
		private function useItemH(e :Event):void
		{
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:12}));
			
			AppEventDispatcher.getInstance().removeEventListener("Guide_use_item",useItemH);
			//限制区域
			var rectPoint :Point = PlayerCenterListView.closeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PlayerCenterListView.closeBtn.width,PlayerCenterListView.closeBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  PlayerCenterListView.closeBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
			clear();
			//enable
			MainView.playerSearchBtn.mouseEnabled = true;
			MainView.bagBtn.mouseEnabled = true;
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener("Guide_openPhysicalUse",clickRestore);
			GlobalDef.GameStage.removeEventListener(ListEvent.ITEM_CLICK,itemClickh);
			AppEventDispatcher.getInstance().removeEventListener("Guide_use_item",useItemH);
			AppEventDispatcher.getInstance().removeEventListener(PlayerCenterEvent.REMOVE_MODEL,onRemoveModuleHandler);
			super.clear();
		}
	}
}